package com.sunfeng.n6;

import lombok.extern.slf4j.Slf4j;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 测试延时
 *
 * @author sunfeng
 * @date 2021/03/03 13:53
 **/
@Slf4j(topic = "c.TestTimer")
public class TestTimer {
    public static void main(String[] args) {
        Timer timer = new Timer();

        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                try {
                    log.debug("task 1");
                    int i = 1 / 0;
                } catch (Exception e) {
                log.error("{}",e.toString());

                }

            }
        };
        TimerTask timerTask2 = new TimerTask() {
            @Override
            public void run() {
                log.debug("task 2");
            }
        };
        log.debug("start");
        timer.schedule(timerTask, 1000);
        timer.schedule(timerTask2, 1000);


    }
}
